#ifndef SQLCONNPOOL_H
#define SQLCONNPOOL_H
#include <mysql/mysql.h>
#include <memory>
#include <string>
#include "log/Logger.h" 
#include "blockqueue.h"
#include "sqlconn.h"
class  CSqlConnPool
{
public: 
    static CSqlConnPool* GetInstance(int maxCapacity = 1024);
    std::shared_ptr<CSqlConn> getConn();

private:
     explicit CSqlConnPool(int maxCapacity);
     ~CSqlConnPool();
     CSqlConnPool(const CSqlConnPool& other) = delete ;
     CSqlConnPool& operator = (const CSqlConnPool& other)=delete;
     
     bool loadConfigFile();
     //专门用于产生新连接的线程
     void produceConnTask();
     //扫描超过最大空闲maxIDleTime的连接,对其进行回收
     void scannerConnTask();
     //添加新连接
     void addConn();

private:
    static CSqlConnPool* m_pInstance;
    std::string m_ip;
    uint16_t m_port;
    std::string m_user;
    std::string m_pwd;
    std::string m_dbName;
    
    size_t m_initSize; //初始化连接数
    size_t m_maxIdleTime; //最大空闲时间
    size_t m_conTimeCount;  //超时时间

    CBlockQueue<CSqlConn* > m_connQue;

};
#endif